﻿@{
	ViewBag.Title = @Resources.PayConferenceFee;
}
<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
	<tr>
		<td class="b1">
			<div>
				<p><img src="~/images/icon_06.png" align="absmiddle" />&nbsp;@Resources.Menu_UserCenter<span>&nbsp;>>&nbsp;</span>@Resources.PayConferenceFee
			</div>
		</td>
	</tr>
	<tr>
		<td class="b4">
			<div class="c">
				<div class="right" id="mainFrame">
					<div class="right_cont">
						<div id="dataGrid"></div>
						<div id="toolBar">
							<div id="searchBar">
								<div style="float: left; display: inline; padding: 5px 5px; font-weight: bold; text-align: left;">
									@Resources.ConferenceName：<input id="queryConferenceName" class="easyui-textbox" style="height:27px; width:200px;">&nbsp;&nbsp;
									@Resources.PaidStatus：<select id="queryHasPaid" name="queryHasPaid" class="easyui-combobox" style="height:27px; width:200px;" data-options="editable:false,panelHeight:'auto'">
										<option value="@ConstValues.strSpace">@Resources.All</option>
										<option value="@ConstValues.PaidStatus.已缴费">@Resources.HasPaid</option>
										<option value="@ConstValues.PaidStatus.未缴费">@Resources.HasNotPaid</option>
									</select>&nbsp;&nbsp;
									<a class="easyui-linkbutton" iconcls="icon-search" onclick="searchData()">@Resources.Search </a>
								</div>
							</div>
							<div id="menuBar"></div>
							<div class="clear"></div>
						</div>
					</div>
				</div>
			</div>
		</td>
	</tr>
</table>
<!-- 费用画面 start -->
<div id="paymentDetailWindow" class="easyui-window"
     title="@Resources.CheckAttendConferenceInfo" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
     style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="paymentDetailWindowTitle" class="tit01"></h3>
			<div id="paymentDataGrid"></div>
		</div>
	</div>
</div>
<!-- 费用画面 end -->
<!-- 缴费画面 start -->
<div id="payWindow" class="easyui-window"
	title="@Resources.CheckAttendConferenceInfo" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="payWindowTitle" class="tit01"></h3>
			<form id="alipaysubmit" name="alipaysubmit" action="https://www.alipay.com/cooperate/gateway.do?" method="get">
				<input type="hidden" id="hidservice" name="service" />
				<input type="hidden" id="hidpartner" name="partner" />
				<input type="hidden" id="hidseller_id" name="seller_id" />
				<input type="hidden" id="hid_input_charset" name="_input_charset" />
				<input type="hidden" id="hidpayment_type" name="payment_type" />
				<input type="hidden" id="hidnotify_url" name="notify_url" />
				<input type="hidden" id="hidreturn_url" name="return_url" />
				<input type="hidden" id="hidsubject" name="subject" />
				<input type="hidden" id="hidsign_type" name="sign_type" />
				<input type="hidden" id="hidsign" name="sign" />
				<input type="hidden" id="hidout_trade_no" name="out_trade_no" />
				<input type="hidden" id="hidtotal_fee" name="total_fee" />
				<input type="hidden" id="hidbody" name="body" />
				<input type="submit" value="支付宝" style="display:none;">
			</form>
			<form id="epaysubmit" name="epaysubmit" action="https://pay.yizhifubj.com/customer/i18n/i18n_raw_order3_0.jsp" method="get">
				<input type="hidden" id="v_mid" name="v_mid" />
				<input type="hidden" id="v_oid" name="v_oid" />
				<input type="hidden" id="v_rcvname" name="v_rcvname" />
				<input type="hidden" id="v_rcvaddr" name="v_rcvaddr" />
				<input type="hidden" id="v_rcvtel" name="v_rcvtel" />
				<input type="hidden" id="v_rcvpost" name="v_rcvpost" />
				<input type="hidden" id="v_amount" name="v_amount" />
				<input type="hidden" id="v_ymd" name="v_ymd" />
				<input type="hidden" id="v_orderstatus" name="v_orderstatus" />
				<input type="hidden" id="v_ordername" name="v_ordername" />
				<input type="hidden" id="v_url" name="v_url" />
				<input type="hidden" id="v_moneytype" name="v_moneytype" />
				<input type="hidden" id="v_md5info" name="v_md5info" />
				<input type="hidden" id="v_language" name="v_language" />
				<input type="submit" value="易支付" style="display:none;">
			</form>
			<form id="paypalsubmit" name="paypalsubmit" action="https://www.paypal.com/cgi-bin/webscr" method="post">
				<div style="display:none;">								
					<input type="text" name="cmd" value="_xclick" />
					<input type="hidden" id="p_business" name="business" />
					<input type="hidden" id="p_cert_id" name="cert_id" />
					<input type="hidden" id="p_item_name" name="item_name" />
					<input type="hidden" id="p_item_number" name="item_number" />
					<input type="hidden" id="p_amount" name="amount" />
					<input type="hidden" id="p_currency_code" name="currency_code" />
					<input type="hidden" id="p_charset" name="charset" />
					<input type="hidden" id="p_return" name="return" />
					<input type="hidden" id="p_cancel_return" name="cancel_return" />
					<input type="hidden" id="p_notify_url" name="notify_url" />
					<input type="hidden" id="p_image_url" name="image_url" />
				</div>
			</form>
			<form id="payDetail" method="post">
				@Html.AntiForgeryToken()							
				<div id="payDetailSec"></div>
				<table width="100%" height="100%" id="visatblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">								
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.PaidType：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="payType" name="PaymentTypeId" class="easyui-combobox" style="height:27px; width:300px;" />
							<input type="hidden"  id="conferenceIdPay">
							<input type="hidden"  id="conferenceAttendIdPay">									
						</td>
						<td style="text-align: right;" class="w1 c1"></td>
						<td style="text-align: left;" class="w2 c2"></td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<span style="color:#DC143C;text-align:center">@Resources.MsgPay</span><br />
				<input type="button" style="margin-top:20px" class="gbtn" id="payButton" onclick="pay();" value="@Resources.Pay" />&nbsp;&nbsp;
				<input type="button" style="margin-top:20px" class="rbtn" onclick="$('#payWindow').window('close');" value=@Resources.Cancel />
			</div>
		</div>
	</div>
</div>
<!-- 缴费画面 end -->

@section Scripts {
<script>
	var windowHeight = $(window).height() - 200;
	$("#mainFrame").css("height", (windowHeight)+"px");

	$(function () {
		$("#queryConferenceName").textbox("textbox").bind("keydown", function(e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ProfileConferenceAttendPayController.GetData),
					nameof(ProfileConferenceAttendPayController).GetControllerName())",
			method: "get",
			singleSelect: true,
			fitColumns: true,
			width: 1200,
			height: $(window).height() - 110,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100,
			pageList: [100, 200, 300, 400, 500],
			columns: [[
				{
					field: "conferenceName", title: "@Resources.ConferenceName", align: "center", sortable: true, width: 250,
					formatter: function (value, rec) {
						var conStr = ""
						if (rec.homePageUrl != null && rec.homePageUrl != "") {
							conStr += "<a href=' "+ rec.homePageUrl +" ' style='color:#1874CD;text-decoration:underline;' target='_blank'>" + value + "</a>  "
						} else {
							var tmp = rec.conferenceNickName == null ? "" : rec.conferenceNickName.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
							conStr += "<a href='@Url.Action(nameof(MeetingMainController.Index), nameof(MeetingMainController).GetControllerName())"
									+ "/" + tmp + "' style='color:#1874CD;text-decoration:underline;' target='_blank'>" + value + "</a>  ";
						}
						return conStr;
					}
				},
				{ field: "fullName", title: "@Resources.FullName", align: "center", sortable: true, width: 200 },
				{ field: "currency", title: "@Resources.Currency", align: "center", sortable: true, width: 100 },
				{
					field: "totalFee", title: "@Resources.Fee", align: "center", sortable: true, width: 180,
					formatter: function (value, rec) {
						if (value != null) {
							var strInfo = "<a href='#' style='color:#1874CD;text-decoration:underline;' onclick='checkPaymentDetail(\"" + rec.id + "\")'>" + value + "</a>  ";
							return strInfo;
						} else {
							return "@ConstValues.strHyphen@ConstValues.strHyphen"
						}
					}
				},
				{
					field: "hasPaid", title: "@Resources.PaidStatus", align: "center", sortable: true, width: 180,
					formatter: function (value, rec) {
						if (value == true) {
							return "@Resources.HasPaid";
						} else {
							var date = new Date();
							var strInfo = "";
							var seperator1 = "-";
							var seperator2 = ":";
							var month = date.getMonth() + 1;
							var strDate = date.getDate();
							if (month >= 1 && month <= 9) {
								month = "0" + month;
							}
							if (strDate >= 0 && strDate <= 9) {
								strDate = "0" + strDate;
							}
							var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate

							if (currentdate < rec.payStartDate || currentdate > rec.payEndDate) {
								strInfo = "@Resources.PayTimeLimit";
							} else {
								strInfo = "<a href='#' style='color:#1874CD;text-decoration:underline;' onclick='payOnLine(\"" + rec.totalFee + "\",\"" + rec.conferenceId + "\",\"" + rec.id + "\",\"" + rec.payName + "\",\"" + rec.payLanguage + "\")'>@Resources.PaidOnLine</a>  ";
							}
							return strInfo;
						}
					}
				},
				{ field: "createDate", title: "@Resources.SubmitTime", align: "center", sortable: true, width: 180 },
			]]
		});
		$("#payWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});
		$("#paymentDetailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});
	});

	function payOnLine(totalFee, conferenceId, id, payName, payLanguage) {
		$("#payWindowTitle").text("@Resources.PaidOnLine");
		$("#conferenceIdPay").val(conferenceId);
		$("#conferenceAttendIdPay").val(id);
		$("#payType").combobox({
			required: true,
			editable: false,
			valueField: "id",
			textField: "name",
			url: "@Url.Action(nameof(UtilityController.GetOnlinePayType), nameof(UtilityController).GetControllerName())"
					+ "?conferenceId=" + conferenceId,
			onLoadSuccess: function(data) {
				orgCount = data.length;
			},
			onShowPanel: function () {
				if (orgCount < 10) {
					$(this).combobox("panel").height("auto");
				} else {
					$(this).combobox("panel").height(200);
				}
			}
		});
		$("#payButton").show();

		$("#payDetailSec").datagrid({
			url: "@Url.Action(nameof(ProfileConferenceAttendPayController.GetPaymentInfoData),
					nameof(ProfileConferenceAttendPayController).GetControllerName())" + "/" + id,
			method: "get",
			singleSelect: true,
			fitColumns: true,
			nowrap: false,
			pageSize: 10,
			striped: true,
			columns: [[
				{ field: "number", title: "", align: "center", halign: "center", width: 40 },
				{ field: "name", title: "@Resources.FeeName", align: "left", halign: "center", width: 1050 },
				{ field: "currency", title: "", align: "center", halign: "center", width: 50 },
				{
					field: "fee", title: "@Resources.Fee", align: "left", halign: "center", width: 350,
					formatter:function(value,rec){
						if (value == null) {
							return "--"
						}
						value = value.toFixed(2).replace(/\d(?=(?:\d{3})+\b)/g,'$&,');
						return value;
					}
				},
			]],
			onLoadSuccess: function(data) {
				if (data.rows.length > 0) {
					$(this).datagrid("appendRow", {
						number: "@Resources.TotalFee：",
						currency:  data.rows[0].currency,
						name: null,
						fee: compute("fee",$(this)) ,
					});

					var tr = $(this).datagrid("getPanel").find("div.datagrid-body tr");
					var lastIndex = tr.length - 1;
					var lastTdIndex = (tr.length / 2  )- 1
					tr.find("td:eq(0)")[lastIndex].setAttribute("colspan","2");
					tr.find("td:eq(1)")[lastIndex].remove();
					tr.find("div:eq(0)")[lastIndex].setAttribute("class","");
					tr.find("div:eq(0)")[lastIndex].setAttribute("style","font-size:14px;text-align:right");
					//tr.find("td:eq(0)")[lastTdIndex].remove()
				}
			},
		});
		$("#payWindow").window("open");
	};

	function pay() {
		var isValid = $("#payDetail").form("validate");
		var payType = $("#payType").combobox("getText");
		var conferenceId = $("#conferenceIdPay").val();
		var attendenceId = $("#conferenceAttendIdPay").val();
		if (isValid) {
			if (payType == "@ConstValues.PayType.AliPay" || payType == "@ConstValues.PayType.支付宝") {
				var url = "@Url.Action(nameof(ProfileAttendenceInfoController.Alipay),
						nameof(ProfileAttendenceInfoController).GetControllerName())"
						+ "?conferenceId=" + conferenceId +  "&attendenceId=" + attendenceId;
				$.get(encodeURI(url), null, function (data, textStatus, jqXHR) {
					if (data.result == "@ConstValues.AjaxFailResult") {
						common.showError(data.message);
					} else {
						$("#hidtotal_fee").val(data.data.fee);
						$("#hidservice").val(data.data.service);
						$("#hidpartner").val(data.data.partner);
						$("#hidseller_id").val(data.data.seller_id);
						$("#hid_input_charset").val(data.data.input_charset);
						$("#hidpayment_type").val(data.data.payment_type);
						$("#hidnotify_url").val(data.data.notify_url);
						$("#hidreturn_url").val(data.data.return_url);
						$("#hidsign_type").val(data.data.sign_type);
						$("#hidsign").val(data.data.sign);
						$("#hidsubject").val(data.data.subject);
						$("#hidout_trade_no").val(data.data.out_trade_no);
						$("#hidbody").val(data.data.body);
						document.forms["alipaysubmit"].submit();
					}
				});
			} else if (payType == "@ConstValues.PayType.PayEase" || payType == "@ConstValues.PayType.易支付") {
				var url = "@Url.Action(nameof(ProfileAttendenceInfoController.Epay),
						nameof(ProfileAttendenceInfoController).GetControllerName())"
						+ "?conferenceId=" + conferenceId +  "&attendenceId=" + attendenceId;
				$.get(encodeURI(url), null, function (data, textStatus, jqXHR) {
					if (data.result == "@ConstValues.AjaxFailResult") {
						common.showError(data.message);
					} else {
						$("#v_mid").val(data.data.tenantId);//商户编号
						$("#v_oid").val(data.data.v_oid);//订单编号
						$("#v_rcvname").val(data.data.tenantId);//收货人姓名
						$("#v_rcvaddr").val(data.data.tenantAddress);//收货人地址
						$("#v_rcvtel").val(data.data.tenantPhone);//收货人电话
						$("#v_rcvpost").val(data.data.postcode);//编码
						$("#v_amount").val(data.data.fee);//订单金额
						$("#v_ymd").val(data.data.createDate);//订单日期
						$("#v_orderstatus").val("1");//配货状态
						$("#v_ordername").val(data.data.v_ordername);//订货人姓名
						$("#v_moneytype").val(data.data.v_moneytype);//支付币种
						$("#v_url").val(data.data.v_url);//返回地址
						$("#v_md5info").val(data.data.v_md5info);//订单加密
						$("#v_language").val(data.data.v_language);
						document.forms["epaysubmit"].submit();
					}
				});
			} else if (payType == "@ConstValues.PayType.PayPal" || payType == "@ConstValues.PayType.贝宝") {
				var url = "@Url.Action(nameof(ProfileAttendenceInfoController.Paypal),
				nameof(ProfileAttendenceInfoController).GetControllerName())"
				+ "?conferenceId=" + conferenceId +  "&attendenceId=" + attendenceId;
				$.get(encodeURI(url), null, function (data, textStatus, jqXHR) {
					if (data.result == "@ConstValues.AjaxFailResult") {
						common.showError(data.message);
					} else {
						$("#p_business").val(data.data.business);//paypay帐号
						$("#p_cert_id").val(data.data.cert_id);//证书号
						$("#p_item_name").val(data.data.item_name);//订单信息
						$("#p_item_number").val(data.data.item_number);//订单编号
						$("#p_amount").val(data.data.amount);//订单总金额
						$("#p_currency_code").val("USD");//订单币种
						$("#p_charset").val("utf-8");//编码格式
						$("#p_return").val("@ConstValues.PaySuccess");//返回的路径
						$("#p_cancel_return").val(data.data.cancel_return);//取消后返回的页面
						$("#p_notify_url").val(data.data.notify_url);//这里告诉paypal付款的通信url,即当客户付款后调用这个url通知系统
						$("#p_image_url").val("https://www.paypal.com/en_US/i/btn/x-click-but23.gif");//如果没有则显示邮箱的账户
						document.forms["paypalsubmit"].submit();
					}
				});
			}
		}

		$("#payWindow").window("close");
	}

	function saveData() {
		$("#frmDetail").form({
			iframe: false,
			success: function (data) { }
		});

		$("#frmDetail").form("submit", {
			onSubmit: function (params) {
				var isValid = $(this).form("validate");
				if (isValid) {
					$.messager.confirm("支付确认", "@Resources.CfmPay?", function (r) {
						if (r) {
							data = JSON.parse(data);
							if (data.result == "@ConstValues.AjaxFailResult") {
								common.showError(data.message);
							} else {
								common.showSuccess(data.message, true);
								$("#detailWindow").window("close");
								$("#dataGrid").datagrid("reload");
								return true;
							}
						}
					});
				}
				return false;
			},
			success: function () {
			},
		});
	};

	function searchData(){
		$("#hidSelect").val("select");
		$("#dataGrid").datagrid("load", {
			queryConferenceName: $("#queryConferenceName").textbox("getValue"),
			queryHasPaid:$("#queryHasPaid").combobox("getValue"),
		});
	}

	function checkPaymentDetail(id) {
		$("#paymentDataGrid").datagrid({
			url: "@Url.Action(nameof(ProfileConferenceAttendPayController.GetPaymentInfoData),
					nameof(ProfileConferenceAttendPayController).GetControllerName())" + "/" + id,
			method: "get",
			singleSelect: true,
			fitColumns: true,
			nowrap: false,
			pagination: false,
			pageSize: 10,
			striped: true,
			columns: [[
				{ field: "number", title: "", align: "center", halign: "center", width: 40 },
				{ field: "name", title: "@Resources.FeeName", align: "left", halign: "center", width: 1050 },
				{ field: "currency", title: "", align: "center", halign: "center", width: 50 },
				{
					field: "fee", title: "@Resources.Fee", align: "left", halign: "center", width: 350,
					formatter:function(value,rec){
						if (value == null) {
							return "--";
						}
						value = value.toFixed(2).replace(/\d(?=(?:\d{3})+\b)/g,'$&,');
						return value;
					}
				},
			]],
			onLoadSuccess: function(data) {
				if (data.rows.length > 0) {
					$(this).datagrid("appendRow", {
						number: "@Resources.TotalFee：",
						currency:  data.rows[0].currency,
						name: null,
						fee: compute("fee",$(this)) ,
					});

					var tr = $(this).datagrid("getPanel").find("div.datagrid-body tr");
					var lastIndex = tr.length - 1;
					var lastTdIndex = (tr.length / 2  )- 1
					tr.find("td:eq(0)")[lastIndex].setAttribute("colspan","2");
					tr.find("td:eq(1)")[lastIndex].remove();
					tr.find("div:eq(0)")[lastIndex].setAttribute("class","");
					tr.find("div:eq(0)")[lastIndex].setAttribute("style","font-size:14px;text-align:right");
					//tr.find("td:eq(0)")[lastTdIndex].remove()
				}
			},
		});
		$("#paymentDetailWindowTitle").text("@Resources.PayConferenceFee");
		$("#paymentDetailWindow").window("open");
	}
</script>
}